/**
 * @Author 12629
 * @Description：
 */
public class Test3 {


    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        return n * fac(n-1);
    }
    //123
    public static void func(int n) {
        if(n < 10) {
            System.out.println(n);
            return;
        }
        func(n/10);
        System.out.println(n % 10);
    }

    public static int sum(int n) {
        if(n == 1) {
            return 1;
        }
        return n + sum(n-1);
    }

    public static int func2(int n) {
        if(n < 10) {
            return n;
        }
        return n % 10 + func2(n/10);
    }

    static int count = 0;
    public static int fib(int n) {
        if(n == 1 || n == 2) {
            count++;
            return 1;
        }
        return fib(n-1) + fib(n-2);
    }
    //迭代 -》 循环的意思
    public static int fib2(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main(String[] args) {
        System.out.println(fib2(1));
        System.out.println(fib2(40));
        System.out.println(count);
    }
}
